#include <bits/stdc++.h>

#define eb emplace_back
#define ep emplace
#define fi first
#define se second
#define in read<int>()
#define lin read<ll>()
#define rep(i, x, y) for(int i = (x); i <= (y); i++)
#define per(i, x, y) for(int i = (x); i >= (y); i--)

using namespace std;

using ll = long long;
using db = double;
using pii = pair < int, int >;
using vec = vector < int >;
using veg = vector < pii >;

template < typename T > T read() {
	T x = 0; bool f = 0; char ch = getchar();
	while(!isdigit(ch)) f |= ch == '-', ch = getchar();
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar();
	return f ? -x : x;
}

template < typename T > void chkmax(T &x, const T &y) { x = x > y ? x : y; }
template < typename T > void chkmin(T &x, const T &y) { x = x < y ? x : y; }

const int N = 110;

int f[N][N], lef[N][N], rig[N][N], n, m;

int main() {
#ifndef ONLINE_JUDGE
	freopen("1.in", "r", stdin);
#endif
	n = in, m = in;
	rep(i, 1, n) {
		int t = in;
		while(t--) {
			int l = in, r = in;
			rep(j, l, r) lef[i][j] = l, rig[i][j] = r;
		}
	}
	rep(len, 1, m) {
		rep(l, 1, m - len + 1) {
			int r = l + len - 1;
			rep(k, l, r) {
				int tot = 0;
				rep(i, 1, n) if(lef[i][k] >= l && rig[i][k] <= r) tot++;
				chkmax(f[l][r], f[l][k - 1] + f[k + 1][r] + tot * tot);
			}
		}
	} printf("%d\n", f[1][m]);
	return 0;
}
